<template>
  <scroll-view
    scroll-y
    @scrolltolower="handleTOLower"
    class="album_scroll_view"
  >
    <!-- 轮播图 开始 -->
    <view class="album_swiper">
      <swiper autoplay indicator-dots circular>
        <swiper-item v-for="item in banner" :key="item.id">
          <image :src="item.thumb"></image>
        </swiper-item>
      </swiper>
    </view>
    <!-- 轮播图 结束 -->

    <!-- 专辑列表  开始 -->
    <view class="album_list">
      <navigator 
          class="album_item" 
          v-for="item in album" 
          :key="item.id" 
          :url="`/pages/album/index?id=${item.id}`">
        <view class="album_img">
          <image :src="item.cover" mode="aspectFill"></image>
        </view>
        <view class="album_info">
          <view class="album_name">{{ item.name }}</view>
          <view class="album_desc">{{ item.desc }}</view>
          <view class="album_button">
            <view class="album_attension">关注</view>
          </view>
        </view>
      </navigator>
    </view>

    <!-- 专辑列表  结束 -->
  </scroll-view>
</template>

<script>
export default {
  data() {
    return {
      params: {
        limit: 30,
        order: "new",
        skip: 0,
      },
      banner: [], //轮播图
      album: [], //推荐列表

      hasMore: true,
    };
  },
  mounted() {
    uni.setNavigationBarTitle({ title: "专辑" });
    this.getList();
  },
  methods: {
    getList() {
      this.request({
        url: "http://157.122.54.189:9088/image/v1/wallpaper/album",
        data: this.params,
      }).then((result) => {
        console.log(result);
        //后台没有数据的话就不再发送请求
        if (result.res.album.length === 0) {
          this.hasMore = false;
          uni.showToast({
        title: "没有数据啦",
        icon: "none",
      });
          return;
        }

        //banner数据只需存储一次
        if (this.banner.length === 0) {
          this.banner = result.res.banner;
        }

        this.album = [...this.album, ...result.res.album];
      });
    },
    handleTOLower() {
      if (this.hasMore) {
        this.params.skip += this.params.limit;
        this.getList();
      } else {
        uni.showToast({
          title: "我是有底线的",
          icon: "none",
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.album_scroll_view {
  height: calc(100vh - 36px);
}
.album_swiper {
  swiper {
    height: 326.1rpx;
    image {
      height: 100%;
    }
  }
}
.album_list {
  padding: 10rpx;
  .album_item {
    padding: 10rpx 0;
    display: flex;
    border-bottom: 1rpx solid #cccccc;
    .album_img {
      flex: 1;
      padding: 10rpx;
      image {
        width: 200rpx;
        height: 200rpx;
      }
    }

    .album_info {
      flex: 2;
      overflow: hidden;
      padding: 0 10rpx;
      .album_name {
        font-size: 30rpx;
        color: #000;
        padding: 10rpx 0;
      }

      .album_desc {
        padding: 10rpx 0;
        font-size: 24rpx;

        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
      }

      .album_button {
        display: flex;
        padding: 10rpx;
        justify-content: flex-end;
        .album_attension {
          color: $color;
          padding: 10rpx;
          border: 1rpx solid $color;
        }
      }
    }
  }
}
</style>
